import { configureStore } from '@reduxjs/toolkit'

// *撤销/重做
import undoable, { excludeAction, StateWithHistory } from 'redux-undo'

// *问卷组件列表
import componentsReducer, { ComponentsStateType } from './componentsReducer'

//* 问卷信息
import pageInfoReducer, { PageInfoType } from './pageInfoReducer'

import userReducer, { UserStateType } from './userReducer'

export type StateType = {
  user: UserStateType
  components: StateWithHistory<ComponentsStateType> //增加了undo之后的类型
  pageInfo: PageInfoType
}

export default configureStore({
  reducer: {
    user: userReducer,

    // * 没有undo
    // components: componentsReducer,
    //*增加了undo
    components: undoable(componentsReducer, {
      limit: 20, //限制undo20步,
      filter: excludeAction([
        'components/resetComponents',
        'components/changeSelectedId',
        'components/selectPrevComponent',
        'components/selectNextComponent',
      ]),
    }),

    // *页面信息
    pageInfo: pageInfoReducer,
  },
})
